/*
********************************************************************************
*
* File : amp6100br.h
*
* Date : 2022/08/14
*
* Revision : 1.0.1
*
* Usage: The header file for the sensor AMP6100 configuration and operation interface.
*
*******************************************************************************/
#ifndef __AMP612XBR_H
#define __AMP612XBR_H

#include "bsp_i2c_gpio.h"
#include "n32g45x.h"

#define AMP612_FAULT  						0x08

#define AMP612XBR_DEV_ID      0x78

#define AMP612X_osr_p_default         16       /* osr_p: default=16, range: 1,2,4,8,16,32,64,128    */
#define AMP612X_osr_t_default          4       /* osr_t: default=4,  range: 4,8                     */
#define AMP612X_IIR_filter_default     8       /* IIR filter: default=8, range: 1~32                */
#define AMP612X_odr_default            1       /* Output data rate: default=1Hz, range: 1~100Hz     */

#define AMP6120_TMP_MIN	      -400             /* -40.0 Celsius */
#define AMP6120_TMP_MAX	      1500             /* 150.0 Celsius */
#define AMP6127_TMP_MIN	      -400             /* -40.0 Celsius */
#define AMP6127_TMP_MAX	      1500             /* 150.0 Celsius */

#define AMP6120_PRS_MIN	     20000             /*  20,000 Pa    */
#define AMP6120_PRS_MAX	    120000             /* 120,000 Pa    */
#define AMP6127_PRS_MIN	        20             /*   20 kPa      */
#define AMP6127_PRS_MAX	      1200             /* 1200 kPa      */

/* Sensor operating status information */
typedef union{
    u8 all;
    struct{
        u8 bit0:1;
        u8 bit1:1;
        u8 bit2:1;
        u8 mode:1;
        u8 bit4:1;
        u8 busy:1;
        u8 adcPwr:1;
        u8 bit7:1;
    }bit;
}
amp_stus_t;

typedef struct{
    u8              portID;
    u8              started;
    amp_stus_t      stus;
    
    u16             osr_p;
    u16             osr_t;
    u8              iir_flg;
    u16             odr;            /* Data output rate, unit:1Hz */
    
    s16             tempDat_max;    /* real temperature max data, unit: 0.1 cnetigrade */
    s16             tempDat_min;
    u32             presDat_max;    /* real pressure max data, unit: 1hPa */
    u32             presDat_min;
    
    s16             temp_rt;
    u32             pres_rt;
    
    u16             temp_raw;
    u32             pres_raw;
    
    u8              cmd_pres;
}
amp_object_t;
extern amp_object_t amp_entity;

/** Global function Declarations */
void Amp_Control_Req(u8 cmd);
void Amp_ADC_Start(u8 en);
void Amp_IIR_Enable(u8 en);
void Amp_ODR_Set(u16 freq);
void AmpSensorInit(void);
void SensorSampleOutput(amp_object_t *entity, u16 timebyms);
void AMP612_Altitude(amp_object_t *entity, uint16_t timebyms);

#endif /* End of amp6100br include */
/*******************END OF FILE******************************************************************************/

